Update to rails 4.1

Dominik Sander 10 years ago
parent
commit
b7b3460fd3

+ 1 - 0
.env.example

@@ -2,6 +2,7 @@
2 2
 
3 3
 # Replace the following with the output from "rake secret"
4 4
 APP_SECRET_TOKEN=REPLACE_ME_NOW!
5
+DEVISE_SECRET_TOKEN=REPLACE_ME_NOW!
5 6
 
6 7
 # This is the domain where your Huginn instance will be running. The default should work
7 8
 # for development, but it needs to be changed to your Huginn domain when you deploy to a

+ 11 - 8
Gemfile

@@ -1,12 +1,14 @@
1 1
 source 'https://rubygems.org'
2 2
 
3
-gem 'rails', '3.2.17'
3
+gem 'protected_attributes', '~>1.0.7'
4
+
5
+gem 'rails', '4.1.0'
4 6
 gem 'mysql2', '~> 0.3.13'
5
-gem 'devise', '~> 3.0.0'
7
+gem 'devise', '~> 3.2.4'
6 8
 gem 'kaminari', '~> 0.14.1'
7 9
 gem 'bootstrap-kaminari-views', '~> 0.0.2'
8 10
 gem 'rufus-scheduler', '~> 3.0.7', require: false
9
-gem 'json', '>= 1.7.7'
11
+gem 'json', '~> 1.8.1'
10 12
 gem 'jsonpath', '~> 0.5.3'
11 13
 gem 'twilio-ruby', '~> 3.10.0'
12 14
 gem 'ruby-growl', '~> 4.1.0'
@@ -20,17 +22,17 @@ gem 'daemons', '~> 1.1.9'
20 22
 
21 23
 gem 'foreman', '~> 0.63.0'
22 24
 
23
-gem 'sass-rails',   '~> 3.2.3'
24
-gem 'coffee-rails', '~> 3.2.1'
25
-gem 'uglifier', '>= 1.0.3'
26
-gem 'select2-rails', '~> 3.4.3'
25
+gem 'sass-rails',   '~> 4.0.0'
26
+gem 'coffee-rails', '~> 4.0.0'
27
+gem 'uglifier', '>= 1.3.0'
28
+gem 'select2-rails', '~> 3.5.4'
27 29
 gem 'jquery-rails', '~> 3.0.4'
28 30
 gem 'ace-rails-ap', '~> 2.0.1'
29 31
 
30 32
 # geokit-rails doesn't work with geokit 1.8.X but it specifies ~> 1.5
31 33
 # in its own Gemfile.
32 34
 gem 'geokit', '~> 1.6.7'
33
-gem 'geokit-rails3', '~> 0.1.5'
35
+gem 'geokit-rails', '~> 2.0.0'
34 36
 
35 37
 gem 'kramdown', '~> 1.1.0'
36 38
 gem 'typhoeus', '~> 0.6.3'
@@ -60,6 +62,7 @@ group :development, :test do
60 62
   gem 'rspec'
61 63
   gem 'shoulda-matchers'
62 64
   gem 'rr'
65
+  gem 'delorean'
63 66
   gem 'webmock', require: false
64 67
   gem 'coveralls', require: false
65 68
 end

+ 79 - 75
Gemfile.lock

@@ -12,38 +12,35 @@ GEM
12 12
   remote: https://rubygems.org/
13 13
   specs:
14 14
     ace-rails-ap (2.0.1)
15
-    actionmailer (3.2.17)
16
-      actionpack (= 3.2.17)
15
+    actionmailer (4.1.0)
16
+      actionpack (= 4.1.0)
17
+      actionview (= 4.1.0)
17 18
       mail (~> 2.5.4)
18
-    actionpack (3.2.17)
19
-      activemodel (= 3.2.17)
20
-      activesupport (= 3.2.17)
21
-      builder (~> 3.0.0)
19
+    actionpack (4.1.0)
20
+      actionview (= 4.1.0)
21
+      activesupport (= 4.1.0)
22
+      rack (~> 1.5.2)
23
+      rack-test (~> 0.6.2)
24
+    actionview (4.1.0)
25
+      activesupport (= 4.1.0)
26
+      builder (~> 3.1)
22 27
       erubis (~> 2.7.0)
23
-      journey (~> 1.0.4)
24
-      rack (~> 1.4.5)
25
-      rack-cache (~> 1.2)
26
-      rack-test (~> 0.6.1)
27
-      sprockets (~> 2.2.1)
28
-    activemodel (3.2.17)
29
-      activesupport (= 3.2.17)
30
-      builder (~> 3.0.0)
31
-    activerecord (3.2.17)
32
-      activemodel (= 3.2.17)
33
-      activesupport (= 3.2.17)
34
-      arel (~> 3.0.2)
35
-      tzinfo (~> 0.3.29)
36
-    activeresource (3.2.17)
37
-      activemodel (= 3.2.17)
38
-      activesupport (= 3.2.17)
39
-    activesupport (3.2.17)
40
-      i18n (~> 0.6, >= 0.6.4)
41
-      multi_json (~> 1.0)
28
+    activemodel (4.1.0)
29
+      activesupport (= 4.1.0)
30
+      builder (~> 3.1)
31
+    activerecord (4.1.0)
32
+      activemodel (= 4.1.0)
33
+      activesupport (= 4.1.0)
34
+      arel (~> 5.0.0)
35
+    activesupport (4.1.0)
36
+      i18n (~> 0.6, >= 0.6.9)
37
+      json (~> 1.7, >= 1.7.7)
38
+      minitest (~> 5.1)
39
+      thread_safe (~> 0.1)
40
+      tzinfo (~> 1.1)
42 41
     addressable (2.3.6)
43
-    arel (3.0.3)
42
+    arel (5.0.1.20140414130214)
44 43
     bcrypt (3.1.7)
45
-    bcrypt-ruby (3.1.5)
46
-      bcrypt (>= 3.1.3)
47 44
     better_errors (1.1.0)
48 45
       coderay (>= 1.0.0)
49 46
       erubis (>= 2.6.6)
@@ -53,11 +50,12 @@ GEM
53 50
       kaminari (>= 0.13)
54 51
       rails (>= 3.1)
55 52
     buftok (0.2.0)
56
-    builder (3.0.4)
53
+    builder (3.2.2)
54
+    chronic (0.10.2)
57 55
     coderay (1.1.0)
58
-    coffee-rails (3.2.2)
56
+    coffee-rails (4.0.1)
59 57
       coffee-script (>= 2.2.0)
60
-      railties (~> 3.2.0)
58
+      railties (>= 4.0.0, < 5.0)
61 59
     coffee-script (2.2.0)
62 60
       coffee-script-source
63 61
       execjs
@@ -78,10 +76,13 @@ GEM
78 76
     delayed_job_active_record (4.0.1)
79 77
       activerecord (>= 3.0, < 4.2)
80 78
       delayed_job (>= 3.0, < 4.1)
81
-    devise (3.0.4)
82
-      bcrypt-ruby (~> 3.0)
79
+    delorean (2.1.0)
80
+      chronic
81
+    devise (3.2.4)
82
+      bcrypt (~> 3.0)
83 83
       orm_adapter (~> 0.1)
84 84
       railties (>= 3.2.6, < 5)
85
+      thread_safe (~> 0.1)
85 86
       warden (~> 1.2.3)
86 87
     diff-lcs (1.2.5)
87 88
     docile (1.1.3)
@@ -116,9 +117,9 @@ GEM
116 117
       thor (>= 0.13.6)
117 118
     geokit (1.6.7)
118 119
       multi_json (>= 1.3.2)
119
-    geokit-rails3 (0.1.5)
120
+    geokit-rails (2.0.1)
120 121
       geokit (~> 1.5)
121
-      rails (~> 3.0)
122
+      rails (>= 3.0)
122 123
     hashie (2.0.5)
123 124
     hike (1.2.3)
124 125
     hipchat (1.1.0)
@@ -130,7 +131,6 @@ GEM
130 131
       json (~> 1.8)
131 132
       multi_xml (>= 0.5.2)
132 133
     i18n (0.6.9)
133
-    journey (1.0.4)
134 134
     jquery-rails (3.0.4)
135 135
       railties (>= 3.0, < 5.0)
136 136
       thor (>= 0.14, < 2.0)
@@ -154,6 +154,7 @@ GEM
154 154
     method_source (0.8.2)
155 155
     mime-types (1.25.1)
156 156
     mini_portile (0.5.3)
157
+    minitest (5.3.3)
157 158
     multi_json (1.9.2)
158 159
     multi_xml (0.5.5)
159 160
     multipart-post (2.0.0)
@@ -169,35 +170,31 @@ GEM
169 170
       rack (~> 1.2)
170 171
     orm_adapter (0.5.0)
171 172
     polyglot (0.3.4)
173
+    protected_attributes (1.0.7)
174
+      activemodel (>= 4.0.1, < 5.0)
172 175
     pry (0.9.12.6)
173 176
       coderay (~> 1.0)
174 177
       method_source (~> 0.8)
175 178
       slop (~> 3.4)
176
-    rack (1.4.5)
177
-    rack-cache (1.2)
178
-      rack (>= 0.4)
179
-    rack-ssl (1.3.4)
180
-      rack
179
+    rack (1.5.2)
181 180
     rack-test (0.6.2)
182 181
       rack (>= 1.0)
183
-    rails (3.2.17)
184
-      actionmailer (= 3.2.17)
185
-      actionpack (= 3.2.17)
186
-      activerecord (= 3.2.17)
187
-      activeresource (= 3.2.17)
188
-      activesupport (= 3.2.17)
189
-      bundler (~> 1.0)
190
-      railties (= 3.2.17)
191
-    railties (3.2.17)
192
-      actionpack (= 3.2.17)
193
-      activesupport (= 3.2.17)
194
-      rack-ssl (~> 1.3.2)
182
+    rails (4.1.0)
183
+      actionmailer (= 4.1.0)
184
+      actionpack (= 4.1.0)
185
+      actionview (= 4.1.0)
186
+      activemodel (= 4.1.0)
187
+      activerecord (= 4.1.0)
188
+      activesupport (= 4.1.0)
189
+      bundler (>= 1.3.0, < 2.0)
190
+      railties (= 4.1.0)
191
+      sprockets-rails (~> 2.0)
192
+    railties (4.1.0)
193
+      actionpack (= 4.1.0)
194
+      activesupport (= 4.1.0)
195 195
       rake (>= 0.8.7)
196
-      rdoc (~> 3.4)
197
-      thor (>= 0.14.6, < 2.0)
198
-    rake (10.2.2)
199
-    rdoc (3.12.2)
200
-      json (~> 1.4)
196
+      thor (>= 0.18.1, < 2.0)
197
+    rake (10.3.1)
201 198
     ref (1.0.5)
202 199
     rest-client (1.6.7)
203 200
       mime-types (>= 1.16)
@@ -227,13 +224,13 @@ GEM
227 224
     rufus-scheduler (3.0.7)
228 225
       tzinfo
229 226
     safe_yaml (1.0.2)
230
-    sass (3.3.5)
231
-    sass-rails (3.2.6)
232
-      railties (~> 3.2.0)
233
-      sass (>= 3.1.10)
234
-      tilt (~> 1.3)
235
-    select2-rails (3.4.9)
236
-      sass-rails
227
+    sass (3.2.19)
228
+    sass-rails (4.0.3)
229
+      railties (>= 4.0.0, < 5.0)
230
+      sass (~> 3.2.0)
231
+      sprockets (~> 2.8, <= 2.11.0)
232
+      sprockets-rails (~> 2.0)
233
+    select2-rails (3.5.4)
237 234
       thor (~> 0.14)
238 235
     shoulda-matchers (2.6.0)
239 236
       activesupport (>= 3.0.0)
@@ -244,11 +241,15 @@ GEM
244 241
       simplecov-html (~> 0.8.0)
245 242
     simplecov-html (0.8.0)
246 243
     slop (3.5.0)
247
-    sprockets (2.2.2)
244
+    sprockets (2.11.0)
248 245
       hike (~> 1.2)
249 246
       multi_json (~> 1.0)
250 247
       rack (~> 1.0)
251 248
       tilt (~> 1.1, != 1.3.0)
249
+    sprockets-rails (2.1.3)
250
+      actionpack (>= 3.0)
251
+      activesupport (>= 3.0)
252
+      sprockets (~> 2.8)
252 253
     systemu (2.6.4)
253 254
     term-ansicolor (1.3.0)
254 255
       tins (~> 1.0)
@@ -279,7 +280,8 @@ GEM
279 280
       simple_oauth (~> 0.2.0)
280 281
     typhoeus (0.6.8)
281 282
       ethon (>= 0.7.0)
282
-    tzinfo (0.3.39)
283
+    tzinfo (1.1.0)
284
+      thread_safe (~> 0.1)
283 285
     uglifier (2.5.0)
284 286
       execjs (>= 0.3.0)
285 287
       json (>= 1.8.0)
@@ -308,43 +310,45 @@ DEPENDENCIES
308 310
   better_errors
309 311
   binding_of_caller
310 312
   bootstrap-kaminari-views (~> 0.0.2)
311
-  coffee-rails (~> 3.2.1)
313
+  coffee-rails (~> 4.0.0)
312 314
   coveralls
313 315
   daemons (~> 1.1.9)
314 316
   delayed_job (~> 4.0.0)
315 317
   delayed_job_active_record (~> 4.0.0)
316
-  devise (~> 3.0.0)
318
+  delorean
319
+  devise (~> 3.2.4)
317 320
   dotenv-rails
318 321
   em-http-request (~> 1.1.2)
319 322
   forecast_io (~> 2.0.0)
320 323
   foreman (~> 0.63.0)
321 324
   geokit (~> 1.6.7)
322
-  geokit-rails3 (~> 0.1.5)
325
+  geokit-rails (~> 2.0.0)
323 326
   hipchat (~> 1.1.0)
324 327
   jquery-rails (~> 3.0.4)
325
-  json (>= 1.7.7)
328
+  json (~> 1.8.1)
326 329
   jsonpath (~> 0.5.3)
327 330
   kaminari (~> 0.14.1)
328 331
   kramdown (~> 1.1.0)
329 332
   mysql2 (~> 0.3.13)
330 333
   nokogiri (~> 1.6.0)
334
+  protected_attributes (~> 1.0.7)
331 335
   pry
332
-  rails (= 3.2.17)
336
+  rails (= 4.1.0)
333 337
   rr
334 338
   rspec
335 339
   rspec-rails
336 340
   rturk (~> 2.11.0)
337 341
   ruby-growl (~> 4.1.0)
338 342
   rufus-scheduler (~> 3.0.7)
339
-  sass-rails (~> 3.2.3)
340
-  select2-rails (~> 3.4.3)
343
+  sass-rails (~> 4.0.0)
344
+  select2-rails (~> 3.5.4)
341 345
   shoulda-matchers
342 346
   therubyracer (~> 0.12.1)
343 347
   twilio-ruby (~> 3.10.0)
344 348
   twitter (~> 5.7.1)
345 349
   twitter-stream!
346 350
   typhoeus (~> 0.6.3)
347
-  uglifier (>= 1.0.3)
351
+  uglifier (>= 1.3.0)
348 352
   webmock
349 353
   weibo_2 (~> 0.1.4)
350 354
   wunderground (~> 1.1.0)

+ 3 - 3
app/models/agent.rb

@@ -39,10 +39,10 @@ class Agent < ActiveRecord::Base
39 39
   after_save :possibly_update_event_expirations
40 40
 
41 41
   belongs_to :user, :inverse_of => :agents
42
-  has_many :events, :dependent => :delete_all, :inverse_of => :agent, :order => "events.id desc"
42
+  has_many :events, -> { order("events.id desc") }, :dependent => :delete_all, :inverse_of => :agent
43 43
   has_one  :most_recent_event, :inverse_of => :agent, :class_name => "Event", :order => "events.id desc"
44
-  has_many :logs, :dependent => :delete_all, :inverse_of => :agent, :class_name => "AgentLog", :order => "agent_logs.id desc"
45
-  has_many :received_events, :through => :sources, :class_name => "Event", :source => :events, :order => "events.id desc"
44
+  has_many :logs,  -> { order("agent_logs.id desc") }, :dependent => :delete_all, :inverse_of => :agent, :class_name => "AgentLog"
45
+  has_many :received_events, -> { order("events.id desc") }, :through => :sources, :class_name => "Event", :source => :events
46 46
   has_many :links_as_source, :dependent => :delete_all, :foreign_key => "source_id", :class_name => "Link", :inverse_of => :source
47 47
   has_many :links_as_receiver, :dependent => :delete_all, :foreign_key => "receiver_id", :class_name => "Link", :inverse_of => :receiver
48 48
   has_many :sources, :through => :links_as_receiver, :class_name => "Agent", :inverse_of => :receivers

+ 2 - 2
app/models/user.rb

@@ -23,8 +23,8 @@ class User < ActiveRecord::Base
23 23
   validates_inclusion_of :invitation_code, :on => :create, :in => INVITATION_CODES, :message => "is not valid"
24 24
 
25 25
   has_many :user_credentials, :dependent => :destroy, :inverse_of => :user
26
-  has_many :events, :order => "events.created_at desc", :dependent => :delete_all, :inverse_of => :user
27
-  has_many :agents, :order => "agents.created_at desc", :dependent => :destroy, :inverse_of => :user
26
+  has_many :events, -> { order("events.created_at desc") }, :dependent => :delete_all, :inverse_of => :user
27
+  has_many :agents, -> { order("agents.created_at desc") }, :dependent => :destroy, :inverse_of => :user
28 28
   has_many :logs, :through => :agents, :class_name => "AgentLog"
29 29
 
30 30
   # Allow users to login via either email or username.

+ 3 - 0
bin/bundle

@@ -0,0 +1,3 @@
1
+#!/usr/bin/env ruby
2
+ENV['BUNDLE_GEMFILE'] ||= File.expand_path('../../Gemfile', __FILE__)
3
+load Gem.bin_path('bundler', 'bundle')

+ 4 - 0
bin/rails

@@ -0,0 +1,4 @@
1
+#!/usr/bin/env ruby
2
+APP_PATH = File.expand_path('../../config/application',  __FILE__)
3
+require_relative '../config/boot'
4
+require 'rails/commands'

+ 4 - 0
bin/rake

@@ -0,0 +1,4 @@
1
+#!/usr/bin/env ruby
2
+require_relative '../config/boot'
3
+require 'rake'
4
+Rake.application.run

+ 1 - 10
config/application.rb

@@ -2,12 +2,7 @@ require File.expand_path('../boot', __FILE__)
2 2
 
3 3
 require 'rails/all'
4 4
 
5
-if defined?(Bundler)
6
-  # If you precompile assets before deploying to production, use this line
7
-  Bundler.require(*Rails.groups(:assets => %w(development test)))
8
-  # If you want your assets lazily compiled in production, use this line
9
-  # Bundler.require(:default, :assets, Rails.env)
10
-end
5
+Bundler.require(:default, Rails.env)
11 6
 
12 7
 module Huginn
13 8
   class Application < Rails::Application
@@ -18,10 +13,6 @@ module Huginn
18 13
     # Custom directories with classes and modules you want to be autoloadable.
19 14
     config.autoload_paths += %W(#{config.root}/lib)
20 15
 
21
-    # Only load the plugins named here, in the order given (default is alphabetical).
22
-    # :all can be used as a placeholder for all plugins not explicitly named.
23
-    # config.plugins = [ :exception_notification, :ssl_requirement, :all ]
24
-
25 16
     # Activate observers that should always be running.
26 17
     # config.active_record.observers = :cacher, :garbage_collector, :forum_observer
27 18
 

+ 7 - 8
config/environments/development.rb

@@ -8,8 +8,11 @@ Huginn::Application.configure do
8 8
   # since you don't have to restart the web server when you make code changes.
9 9
   config.cache_classes = false
10 10
 
11
-  # Log error messages when you accidentally call methods on nil.
12
-  config.whiny_nils = true
11
+  # Eager load code on boot. This eager loads most of Rails and
12
+  # your application in memory, allowing both threaded web servers
13
+  # and those relying on copy on write to perform better.
14
+  # Rake tasks automatically ignore this option for performance.
15
+  config.eager_load = false
13 16
 
14 17
   # Show full error reports and disable caching
15 18
   config.consider_all_requests_local       = true
@@ -24,12 +27,8 @@ Huginn::Application.configure do
24 27
   # Raise exception on mass assignment protection for Active Record models
25 28
   config.active_record.mass_assignment_sanitizer = :strict
26 29
 
27
-  # Log the query plan for queries taking more than this (works
28
-  # with SQLite, MySQL, and PostgreSQL)
29
-  config.active_record.auto_explain_threshold_in_seconds = 0.5
30
-
31
-  # Do not compress assets
32
-  config.assets.compress = false
30
+  # Raise an error on page load if there are pending migrations.
31
+  config.active_record.migration_error = :page_load
33 32
 
34 33
   # Expands the lines which load the assets
35 34
   config.assets.debug = true

+ 28 - 10
config/environments/production.rb

@@ -4,15 +4,27 @@ Huginn::Application.configure do
4 4
   # Code is not reloaded between requests
5 5
   config.cache_classes = true
6 6
 
7
+  # Eager load code on boot. This eager loads most of Rails and
8
+  # your application in memory, allowing both threaded web servers
9
+  # and those relying on copy on write to perform better.
10
+  # Rake tasks automatically ignore this option for performance.
11
+  config.eager_load = true
12
+
7 13
   # Full error reports are disabled and caching is turned on
8 14
   config.consider_all_requests_local       = false
9 15
   config.action_controller.perform_caching = true
10 16
 
17
+  # Enable Rack::Cache to put a simple HTTP cache in front of your application
18
+  # Add `rack-cache` to your Gemfile before enabling this.
19
+  # For large-scale production use, consider using a caching reverse proxy like nginx, varnish or squid.
20
+  # config.action_dispatch.rack_cache = true
21
+
11 22
   # Disable Rails's static asset server (Apache or nginx will already do this)
12 23
   config.serve_static_assets = false
13 24
 
14 25
   # Compress JavaScripts and CSS
15
-  config.assets.compress = true
26
+  config.assets.js_compressor  = :uglifier
27
+  config.assets.css_compressor = :sass
16 28
 
17 29
   # Don't fallback to assets pipeline if a precompiled asset is missed
18 30
   config.assets.compile = false
@@ -20,10 +32,10 @@ Huginn::Application.configure do
20 32
   # Generate digests for assets URLs
21 33
   config.assets.digest = true
22 34
 
23
-  # Defaults to nil and saved in location specified by config.assets.prefix
24
-  # config.assets.manifest = YOUR_PATH
35
+  # Version of your assets, change this if you want to expire all your assets.
36
+  config.assets.version = '1.0'
25 37
 
26
-  # Specifies the header that your server uses for sending files
38
+  # Specifies the header that your server uses for sending files.
27 39
   # config.action_dispatch.x_sendfile_header = "X-Sendfile" # for apache
28 40
   # config.action_dispatch.x_sendfile_header = 'X-Accel-Redirect' # for nginx
29 41
 
@@ -50,19 +62,25 @@ Huginn::Application.configure do
50 62
   # Precompile additional assets (application.js.coffee.erb, application.css, and all non-JS/CSS are already added)
51 63
   config.assets.precompile += %w( graphing.js user_credentials.js )
52 64
 
53
-  # Enable threaded mode
54
-  # config.threadsafe!
65
+  # Ignore bad email addresses and do not raise email delivery errors.
66
+  # Set this to true and configure the email server for immediate delivery to raise delivery errors.
67
+  # config.action_mailer.raise_delivery_errors = false
55 68
 
56 69
   # Enable locale fallbacks for I18n (makes lookups for any locale fall back to
57
-  # the I18n.default_locale when a translation can not be found)
70
+  # the I18n.default_locale when a translation cannot be found).
58 71
   config.i18n.fallbacks = true
59 72
 
60 73
   # Send deprecation notices to registered listeners
61 74
   config.active_support.deprecation = :notify
62 75
 
63
-  # Log the query plan for queries taking more than this (works
64
-  # with SQLite, MySQL, and PostgreSQL)
65
-  # config.active_record.auto_explain_threshold_in_seconds = 0.5
76
+  # Disable automatic flushing of the log to improve performance.
77
+  # config.autoflush_log = false
78
+
79
+  # Use default logging formatter so that PID and timestamp are not suppressed.
80
+  config.log_formatter = ::Logger::Formatter.new
81
+
82
+  # Do not dump schema after migrations.
83
+  config.active_record.dump_schema_after_migration = false
66 84
 
67 85
   config.action_mailer.default_url_options = { :host => ENV['DOMAIN'] }
68 86
   config.action_mailer.asset_host = ENV['DOMAIN']

+ 6 - 4
config/environments/test.rb

@@ -7,13 +7,15 @@ Huginn::Application.configure do
7 7
   # and recreated between test runs. Don't rely on the data there!
8 8
   config.cache_classes = true
9 9
 
10
+  # Do not eager load code on boot. This avoids loading your whole application
11
+  # just for the purpose of running a single test. If you are using a tool that
12
+  # preloads Rails for running tests, you may have to set it to true.
13
+  config.eager_load = false
14
+
10 15
   # Configure static asset server for tests with Cache-Control for performance
11 16
   config.serve_static_assets = true
12 17
   config.static_cache_control = "public, max-age=3600"
13 18
 
14
-  # Log error messages when you accidentally call methods on nil
15
-  config.whiny_nils = true
16
-
17 19
   # Show full error reports and disable caching
18 20
   config.consider_all_requests_local       = true
19 21
   config.action_controller.perform_caching = false
@@ -22,7 +24,7 @@ Huginn::Application.configure do
22 24
   config.action_dispatch.show_exceptions = false
23 25
 
24 26
   # Disable request forgery protection in test environment
25
-  config.action_controller.allow_forgery_protection    = false
27
+  config.action_controller.allow_forgery_protection = false
26 28
 
27 29
   # Tell Action Mailer not to deliver emails to the real world.
28 30
   # The :test delivery method accumulates sent emails in the

+ 13 - 5
config/initializers/devise.rb

@@ -1,9 +1,15 @@
1 1
 # Use this hook to configure devise mailer, warden hooks and so forth.
2 2
 # Many of these configuration options can be set straight in your model.
3 3
 Devise.setup do |config|
4
+  # The secret key used by Devise. Devise uses this key to generate
5
+  # random tokens. Changing this key will render invalid all existing
6
+  # confirmation, reset password and unlock tokens in the database.
7
+  config.secret_key = ENV['DEVISE_SECRET_TOKEN']
8
+
4 9
   # ==> Mailer Configuration
5 10
   # Configure the e-mail address which will be shown in Devise::Mailer,
6
-  # note that it will be overwritten if you use your own mailer class with default "from" parameter.
11
+  # note that it will be overwritten if you use your own mailer class
12
+  # with default "from" parameter.
7 13
   config.mailer_sender = "please-change-me-at-config-initializers-devise@example.com"
8 14
 
9 15
   # Configure the class responsible to send e-mails.
@@ -72,6 +78,12 @@ Devise.setup do |config|
72 78
   # passing :skip => :sessions to `devise_for` in your config/routes.rb
73 79
   config.skip_session_storage = [:http_auth]
74 80
 
81
+  # By default, Devise cleans up the CSRF token on authentication to
82
+  # avoid CSRF token fixation attacks. This means that, when using AJAX
83
+  # requests for sign in and sign up, you need to get a new CSRF token
84
+  # from the server. You can disable this option at your own risk.
85
+  # config.clean_up_csrf_token_on_authentication = true
86
+
75 87
   # ==> Configuration for :database_authenticatable
76 88
   # For bcrypt, this is the cost for hashing the password and defaults to 10. If
77 89
   # using other encryptors, it sets how many times you want the password re-encrypted.
@@ -174,10 +186,6 @@ Devise.setup do |config|
174 186
   # REST_AUTH_SITE_KEY to pepper)
175 187
   # config.encryptor = :sha512
176 188
 
177
-  # ==> Configuration for :token_authenticatable
178
-  # Defines name of the authentication token params key
179
-  # config.token_authentication_key = :auth_token
180
-
181 189
   # ==> Scopes configuration
182 190
   # Turn scoped views on. Before rendering "sessions/new", it will first check for
183 191
   # "users/sessions/new". It's turned off by default because it's slower if you

+ 1 - 1
config/initializers/secret_token.rb

@@ -4,4 +4,4 @@
4 4
 # If you change this key, all old signed cookies will become invalid!
5 5
 # Make sure the secret is at least 30 characters and all random,
6 6
 # no regular words or you'll be exposed to dictionary attacks.
7
-Huginn::Application.config.secret_token = ENV['APP_SECRET_TOKEN']
7
+Huginn::Application.config.secret_key_base = ENV['APP_SECRET_TOKEN']

+ 4 - 4
config/routes.rb

@@ -28,18 +28,18 @@ Huginn::Application.routes.draw do
28 28
 
29 29
   resources :user_credentials, :except => :show
30 30
 
31
-  match "/worker_status" => "worker_status#show"
31
+  get "/worker_status" => "worker_status#show"
32 32
 
33 33
   post "/users/:user_id/update_location/:secret" => "user_location_updates#create"
34 34
 
35
-  match "/users/:user_id/web_requests/:agent_id/:secret" => "web_requests#handle_request", :as => :web_requests
35
+  match  "/users/:user_id/web_requests/:agent_id/:secret" => "web_requests#handle_request", :as => :web_requests, :via => [:get, :post, :put, :delete]
36 36
   post "/users/:user_id/webhooks/:agent_id/:secret" => "web_requests#handle_request" # legacy
37 37
 
38 38
 # To enable DelayedJobWeb, see the 'Enable DelayedJobWeb' section of the README.
39
-#  match "/delayed_job" => DelayedJobWeb, :anchor => false
39
+#  get "/delayed_job" => DelayedJobWeb, :anchor => false
40 40
 
41 41
   devise_for :users, :sign_out_via => [ :post, :delete ]
42 42
 
43
-  match "/about" => "home#about"
43
+  get "/about" => "home#about"
44 44
   root :to => "home#index"
45 45
 end

+ 2 - 2
lib/rdbms_functions.rb

@@ -1,10 +1,10 @@
1 1
 module RDBMSFunctions
2 2
   def rdbms_date_add(source, unit, amount)
3
-    adapter_type = connection.adapter_name.downcase.to_sym
3
+    adapter_type = ActiveRecord::Base.connection.adapter_name.downcase.to_sym
4 4
     case adapter_type
5 5
       when :mysql, :mysql2
6 6
         "DATE_ADD(`#{source}`, INTERVAL #{amount} #{unit})"
7
-      when :postgresql    
7
+      when :postgresql
8 8
         "(#{source} + INTERVAL '#{amount} #{unit}')"
9 9
       else
10 10
         raise NotImplementedError, "Unknown adapter type '#{adapter_type}'"

+ 1 - 1
spec/lib/utils_spec.rb

@@ -97,7 +97,7 @@ describe Utils do
97 97
     it "escapes </script> tags in the output JSON" do
98 98
       cleaned_json = Utils.jsonify(:foo => "bar", :xss => "</script><script>alert('oh no!')</script>")
99 99
       cleaned_json.should_not include("</script>")
100
-      cleaned_json.should include("<\\/script>")
100
+      cleaned_json.should include('\\u003c/script\\u003e')
101 101
     end
102 102
 
103 103
     it "html_safes the output unless :skip_safe is passed in" do

+ 1 - 1
spec/models/agents/hipchat_agent_spec.rb

@@ -62,7 +62,7 @@ describe Agents::HipchatAgent do
62 62
     end
63 63
 
64 64
     it "should merge all options" do
65
-      @checker.send(:merge_options, @event).should == {
65
+      @checker.send(:merge_options, @event).deep_symbolize_keys.should == {
66 66
         :room_name => "test",
67 67
         :username => "Huggin user",
68 68
         :message => "Looks like its going to rain",

+ 19 - 14
spec/models/agents/public_transport_agent_spec.rb

@@ -19,7 +19,6 @@ describe Agents::PublicTransportAgent do
19 19
       stub_request(:get, "http://webservices.nextbus.com/service/publicXMLFeed?a=sf-muni&command=predictionsForMultiStops&stops=N%7C5215").
20 20
          with(:headers => {'User-Agent'=>'Typhoeus - https://github.com/typhoeus/typhoeus'}).
21 21
          to_return(:status => 200, :body => File.read(Rails.root.join("spec/data_fixtures/public_transport_agent.xml")), :headers => {})
22
-      stub(Time).now {"2014-01-14 20:21:30 +0500".to_time}
23 22
     end
24 23
 
25 24
     it "should create 4 events" do
@@ -27,15 +26,18 @@ describe Agents::PublicTransportAgent do
27 26
     end
28 27
 
29 28
     it "should add 4 items to memory" do
30
-      @agent.memory.should == {}
31
-      @agent.check
32
-      @agent.memory.should == {"existing_routes" => [
33
-          {"stopTag"=>"5221", "tripTag"=>"5840324", "epochTime"=>"1389706393991", "currentTime"=>"2014-01-14 20:21:30 +0500"},
34
-          {"stopTag"=>"5221", "tripTag"=>"5840083", "epochTime"=>"1389706512784", "currentTime"=>"2014-01-14 20:21:30 +0500"},
35
-          {"stopTag"=>"5215", "tripTag"=>"5840324", "epochTime"=>"1389706282012", "currentTime"=>"2014-01-14 20:21:30 +0500"},
36
-          {"stopTag"=>"5215", "tripTag"=>"5840083", "epochTime"=>"1389706400805", "currentTime"=>"2014-01-14 20:21:30 +0500"}
37
-        ]
38
-      }
29
+      time_travel_to Time.parse("2014-01-14 20:21:30 +0500") do
30
+        @agent.memory.should == {}
31
+        @agent.check
32
+        @agent.save
33
+        @agent.reload.memory.should == {"existing_routes" => [
34
+            {"stopTag"=>"5221", "tripTag"=>"5840324", "epochTime"=>"1389706393991", "currentTime"=>Time.now.to_s},
35
+            {"stopTag"=>"5221", "tripTag"=>"5840083", "epochTime"=>"1389706512784", "currentTime"=>Time.now.to_s},
36
+            {"stopTag"=>"5215", "tripTag"=>"5840324", "epochTime"=>"1389706282012", "currentTime"=>Time.now.to_s},
37
+            {"stopTag"=>"5215", "tripTag"=>"5840083", "epochTime"=>"1389706400805", "currentTime"=>Time.now.to_s}
38
+          ]
39
+        }
40
+      end
39 41
     end
40 42
 
41 43
     it "should not create events twice" do
@@ -44,10 +46,13 @@ describe Agents::PublicTransportAgent do
44 46
     end
45 47
 
46 48
     it "should reset memory after 2 hours" do
47
-      lambda { @agent.check }.should change {@agent.events.count}.by(4)
48
-      stub(Time).now {"2014-01-14 20:21:30 +0500".to_time + 3.hours}
49
-      @agent.cleanup_old_memory
50
-      lambda { @agent.check }.should change {@agent.events.count}.by(4)
49
+      time_travel_to Time.parse("2014-01-14 20:21:30 +0500") do
50
+        lambda { @agent.check }.should change {@agent.events.count}.by(4)
51
+      end
52
+      time_travel_to "2014-01-14 23:21:30 +0500".to_time do
53
+        @agent.cleanup_old_memory
54
+        lambda { @agent.check }.should change {@agent.events.count}.by(4)
55
+      end
51 56
     end
52 57
   end
53 58
 

+ 1 - 0
spec/spec_helper.rb

@@ -42,4 +42,5 @@ RSpec.configure do |config|
42 42
 
43 43
   config.include Devise::TestHelpers, :type => :controller
44 44
   config.include SpecHelpers
45
+  config.include Delorean
45 46
 end